package com.edu.vod.controller;

import com.edu.common.utils.R;
import com.edu.vod.service.VideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api("视频管理")
@RestController
@RequestMapping("/eduvod/video")
@CrossOrigin
public class VodController {
    @Autowired
    private VideoService videoService;


    /**
     * 视频上传
     * @param file
     * @return
     */
    @ApiOperation("上传视频")
    @PostMapping("/uploadVideo")
    public R uploadVideo(@ApiParam(value = "file",name = "file",required = false)
                             @RequestParam("file") MultipartFile file){

       String videoId = videoService.uploadVideoAly(file);

        return R.ok().message("视频上传成功!").data("videoId",videoId);
    }


    /**
     * 删除视频
     */
    @ApiOperation("删除视频")
    @DeleteMapping("/delVideo/{videoId}")
    public R delVideo(@ApiParam(value = "videoId",name = "videoId",required = true)
                      @PathVariable String videoId){
        videoService.removeVideo(videoId);
        return R.ok().message("删除视频成功!");
    }

    /**
     * 批量删除视频
     * @param videoIdList
     * @return
     */
    @ApiOperation("批量删除视频")
    @DeleteMapping("/delVideoList")
    public R delVideoList(@ApiParam(value = "videoIdList",name = "videoIdList",required = true)
                          @RequestParam("videoIdList")List<String>videoIdList){
            videoService.removeVideoList(videoIdList);
        return R.ok().message("批量删除视频成功!");
    }

}
